[id].vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. <template>
  2. <div id="newsList">
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <!-- Banner1 -->
  6. <HomeBanner1></HomeBanner1>
  7. <!-- 面包屑导航 -->
  8. <div class="breadcrumb">
  9. <div class="inner">
  10. <span class="location">当前位置:</span>
  11. <el-breadcrumb :separator-icon="ArrowRight">
  12. <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
  13. <el-breadcrumb-item :to="{ path: '/newsList' }">{{ name }}</el-breadcrumb-item>
  14. </el-breadcrumb>
  15. </div>
  16. </div>
  17. <!-- 资讯列表 -->
  18. <div class="newsList">
  19. <div class="inner">
  20. <div class="innerLeft">
  21. <ul class="list">
  22. <li v-for="(item, index) in newsList" :key="index">
  23. <NuxtLink :to="`/newsDetail/${item.id}`" target="_blank">{{ item.title }}</NuxtLink>
  24. </li>
  25. </ul>
  26. <!-- 分页器 -->
  27. <div class="pagination">
  28. <el-pagination size="small" background layout="prev, pager, next" :total="total" class="mt-4"
  29. prev-text="上一页" next-text="下一页" @change="changePage" />
  30. <!-- <HomePagination @sendData="handleData"></HomePagination> -->
  31. </div>
  32. </div>
  33. <div class="innerRight">
  34. <DetailHotNews></DetailHotNews>
  35. </div>
  36. </div>
  37. </div>
  38. <!-- 三农资讯logo -->
  39. <HomeSannongzixun></HomeSannongzixun>
  40. <!-- 资讯推荐 -->
  41. <div class="zixuntuijian">
  42. <div class="inner">
  43. <div class="innerLeft">
  44. <div class="zixunLeft">
  45. <!-- 标题部分 -->
  46. <div class="title">
  47. <h3>
  48. 资讯推荐
  49. <!-- <span>查看更多</span> -->
  50. </h3>
  51. </div>
  52. <!-- 图片和文字列表 -->
  53. <ul class="photo_text">
  54. <li v-for="item in news1">
  55. <img :src="item.imgurl" alt="">
  56. <div>
  57. <h5>{{ item.title }}</h5>
  58. <p>
  59. <span>{{ item.author }}</span>
  60. <span>{{ item.created_at }}</span>
  61. </p>
  62. </div>
  63. </li>
  64. <li v-for="item in news11">
  65. <em></em>
  66. {{ item.title }}
  67. </li>
  68. </ul>
  69. </div>
  70. <div class="zixunRight">
  71. <!-- 标题部分 -->
  72. <div class="title">
  73. <h3>
  74. 资讯推荐
  75. <!-- <span>查看更多</span> -->
  76. </h3>
  77. </div>
  78. <!-- 图片和文字列表 -->
  79. <ul class="photo_text">
  80. <li v-for="item in news2">
  81. <img :src="item.imgurl" alt="">
  82. <div>
  83. <h5>{{ item.title }}</h5>
  84. <p>
  85. <span>{{ item.author }}</span>
  86. <span>{{ item.created_at }}</span>
  87. </p>
  88. </div>
  89. </li>
  90. <li v-for="item in news22">
  91. <em></em>
  92. {{ item.title }}
  93. </li>
  94. </ul>
  95. </div>
  96. </div>
  97. <div class="innerRight">
  98. <!-- 标题部分 -->
  99. <div class="title">
  100. <h4>
  101. 热点资讯
  102. <!-- <span>查看更多</span> -->
  103. </h4>
  104. </div>
  105. <!-- 列表 -->
  106. <ul class="rightList">
  107. <li v-for="item in hotlistall">
  108. <img class="left" :src="item.imgurl">
  109. <p class="left">{{ item.title }}</p>
  110. </li>
  111. </ul>
  112. </div>
  113. </div>
  114. </div>
  115. <!-- 页面底部 -->
  116. <HomeFoot></HomeFoot>
  117. </div>
  118. </template>
  119. <script setup>
  120. import { onMounted } from 'vue';
  121. import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus'
  122. import { ArrowRight } from '@element-plus/icons-vue'
  123. const nuxtApp = useNuxtApp();
  124. const axios = nuxtApp.$axios;
  125. //获得跳转过来的id
  126. const route = useRoute();
  127. const articleId = route.params.id; //获得该页面的id
  128. const category_id = route.query.category_id; //获得该页面的id
  129. const name = route.query.name; //获得该页面的id
  130. console.log(name);
  131. //关键词
  132. let keyWord = useState("keyWord", () => "")
  133. let id = useState("id", () => "")
  134. let total = useState("total", () => 0)
  135. let page = useState("page", () => 1)
  136. let pageSize = useState("pageSize", () => 10)
  137. onMounted(() => {
  138. id.value = route.query.id;
  139. console.log('id', id.value);
  140. })
  141. // 页码
  142. // //页面组件传递数据的时间驱动函数
  143. // const handleData = (data) => {
  144. // console.log(data.value)
  145. // page.value = data.value
  146. // //在页码发生变化时去请求响应页面的新闻数据
  147. // axios.get(`/web/getWebsiteArticleList?page=${page.value}&pageSize=${10}&catid=${14}&keyword=${keyWord.value}`).then(response => {
  148. // // console.log(response.data.rows);
  149. // newsList.value = response.data.rows;
  150. // }).catch(error => {
  151. // console.error(error);
  152. // })
  153. // }
  154. let changePage = (value) => {
  155. console.log("当前页码", value);
  156. page.value = value
  157. console.log(page.value);
  158. newslists()
  159. }
  160. // 新闻列表
  161. const newsList = useState("newsList", () => '');
  162. const newslists = async () => {
  163. try {
  164. const response = await axios.get(`/web/getWebsiteArticleList?page=${page.value}&pageSize=${pageSize.value}&catid=${category_id}`);
  165. // console.log(response.data.rows);
  166. newsList.value = response.data.rows;
  167. total.value = response.data.count;
  168. } catch (error) {
  169. console.error(error);
  170. }
  171. }
  172. //热点资讯
  173. const hotlistall = useState("hotlistall", () => "");
  174. const hotlist = async () => {
  175. try {
  176. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${2}&level=${4}&placeid=${1}`);
  177. console.log('热点资讯', response.data);
  178. for (let item of response.data) {
  179. console.log(item);
  180. item.count = 1;
  181. }
  182. hotlistall.value = response.data;
  183. } catch (error) {
  184. console.error(error);
  185. }
  186. }
  187. //资讯推荐1
  188. const news1 = useState("news1", () => "");
  189. const newslist1 = async () => {
  190. try {
  191. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${1}&level=${5}&placeid=${1}`);
  192. console.log('热点资讯', response.data);
  193. news1.value = response.data;
  194. } catch (error) {
  195. console.error(error);
  196. }
  197. }
  198. const news11 = useState("news11", () => "");
  199. const newslist11 = async () => {
  200. try {
  201. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${3}&level=${5}&placeid=${1}`);
  202. console.log('热点资讯', response.data);
  203. news11.value = response.data;
  204. } catch (error) {
  205. console.error(error);
  206. }
  207. }
  208. //资讯推荐2
  209. const news2 = useState("news2", () => "");
  210. const newslist2 = async () => {
  211. try {
  212. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${1}&level=${5}&placeid=${1}`);
  213. console.log('热点资讯', response.data);
  214. news2.value = response.data;
  215. } catch (error) {
  216. console.error(error);
  217. }
  218. }
  219. const news22 = useState("news22", () => "");
  220. const newslist22 = async () => {
  221. try {
  222. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${3}&level=${5}&placeid=${1}`);
  223. console.log('热点资讯', response.data);
  224. news22.value = response.data;
  225. } catch (error) {
  226. console.error(error);
  227. }
  228. }
  229. //挂载成功钩子函数
  230. onMounted(() => {
  231. // 资讯推荐
  232. newslists()
  233. // 热点资讯
  234. hotlist()
  235. // 资讯推荐
  236. newslist1()
  237. newslist2()
  238. // 热点资讯
  239. newslist11()
  240. newslist22()
  241. })
  242. //路由中间件
  243. definePageMeta({
  244. middleware: 'auth'
  245. })
  246. </script>
  247. <style lang="less" scoped>
  248. //导航条
  249. .breadcrumb {
  250. width: 100%;
  251. height: 22px;
  252. margin-bottom: 30px;
  253. font-family: Microsoft YaHei, Microsoft YaHei;
  254. font-weight: 400;
  255. font-size: 20px;
  256. color: #666666;
  257. line-height: 23px;
  258. text-align: left;
  259. font-style: normal;
  260. text-transform: none;
  261. :deep(.el-breadcrumb) {
  262. display: inline-block;
  263. vertical-align: -4px;
  264. }
  265. :deep(.el-breadcrumb__inner a),
  266. :deep(.el-breadcrumb__inner.is-link) {
  267. color: #666666;
  268. font-weight: 400;
  269. text-decoration: none;
  270. transition: var(--el-transition-color);
  271. }
  272. span {
  273. font-family: Microsoft YaHei, Microsoft YaHei;
  274. font-weight: 400;
  275. font-size: 20px;
  276. color: #666666;
  277. line-height: 23px;
  278. text-align: left;
  279. font-style: normal;
  280. text-transform: none;
  281. }
  282. span:hover {
  283. color: #666666;
  284. }
  285. .location {
  286. margin-right: 20px;
  287. width: 100px;
  288. height: 22px;
  289. font-family: Microsoft YaHei, Microsoft YaHei;
  290. font-weight: 400;
  291. font-size: 20px;
  292. color: #666666;
  293. line-height: 23px;
  294. text-align: left;
  295. font-style: normal;
  296. text-transform: none;
  297. }
  298. }
  299. // 资讯列表
  300. .newsList {
  301. width: 100%;
  302. height: 675px;
  303. margin-bottom: 70px;
  304. .inner {
  305. width: 1200px;
  306. .innerLeft,
  307. .innerRight {
  308. border-top: 1px solid #139602;
  309. }
  310. .innerLeft {
  311. height: 675px;
  312. >.list {
  313. height: 570px;
  314. margin-bottom: 70px;
  315. >li {
  316. width: 790px;
  317. height: 56px;
  318. white-space: nowrap;
  319. overflow: hidden;
  320. text-overflow: ellipsis;
  321. line-height: 56px;
  322. border-bottom: 1px solid #D9D9D9;
  323. >a {
  324. width: 360px;
  325. height: 26px;
  326. font-family: Microsoft YaHei, Microsoft YaHei;
  327. font-weight: 400;
  328. font-size: 20px;
  329. color: #333333;
  330. line-height: 26px;
  331. text-align: left;
  332. font-style: normal;
  333. text-transform: none;
  334. }
  335. }
  336. >li:hover>a {
  337. color: #139602;
  338. }
  339. >li:nth-child(1)::after,
  340. >li:nth-child(2)::after {
  341. content: "热";
  342. margin-left: 13px;
  343. background: #FF8A37;
  344. color: #fff;
  345. font-size: 14px;
  346. padding: 0px 2px;
  347. }
  348. }
  349. >.pagination {
  350. width: 800px;
  351. height: 34px;
  352. margin-left: 141px;
  353. display: flex;
  354. justify-content: center;
  355. margin: 0;
  356. // 鼠标移入后字体颜色
  357. .el-pagination::v-deep :hover {
  358. color: #139609;
  359. }
  360. .el-pagination.is-background::v-deep .btn-next,
  361. .el-pagination.is-background::v-deep .btn-prev {
  362. width: 70px;
  363. height: 34px;
  364. margin: 0px 10px;
  365. border-radius: 4px;
  366. }
  367. .el-pagination.is-background::v-deep .el-pager li {
  368. margin: 0px 10px;
  369. width: 38px;
  370. height: 34px;
  371. border-radius: 4px;
  372. }
  373. .el-pagination.is-background::v-deep .btn-next.is-active,
  374. .el-pagination.is-background::v-deep .btn-prev.is-active,
  375. .el-pagination.is-background::v-deep .el-pager li.is-active {
  376. background-color: #028e21;
  377. color: #fff;
  378. }
  379. }
  380. }
  381. .innerRight {
  382. width: 381px;
  383. height: 605px;
  384. }
  385. }
  386. }
  387. //资讯推荐
  388. .zixuntuijian {
  389. width: 100%;
  390. height: 290px;
  391. margin-bottom: 70px;
  392. .innerLeft {
  393. // 左侧
  394. .zixunLeft {
  395. margin-right: 30px;
  396. }
  397. .zixunRight,
  398. .zixunLeft {
  399. float: left;
  400. width: 380px;
  401. height: 290px;
  402. // 标题部分
  403. >.title {
  404. width: 380px;
  405. }
  406. >.title>h3 {
  407. height: 36px;
  408. font-family: Source Han Sans, Source Han Sans;
  409. font-weight: bold;
  410. font-size: 24px;
  411. color: #000000;
  412. line-height: 28px;
  413. text-align: left;
  414. font-style: normal;
  415. text-transform: none;
  416. border-bottom: 1px solid #139602;
  417. }
  418. >.title>h3>span {
  419. float: right;
  420. width: 56px;
  421. height: 20px;
  422. line-height: 24px;
  423. font-weight: 400;
  424. font-size: 14px;
  425. color: #999999;
  426. font-style: normal;
  427. text-transform: none;
  428. }
  429. .photo_text {
  430. >li:first-child {
  431. width: 380px;
  432. height: 120px;
  433. margin-top: 20px;
  434. margin-bottom: 15px;
  435. position: relative;
  436. >img {
  437. float: left;
  438. width: 160px;
  439. height: 120px;
  440. }
  441. >div {
  442. float: left;
  443. width: 220px;
  444. height: 120px;
  445. padding-left: 15px;
  446. padding-top: 6px;
  447. box-sizing: border-box;
  448. background-color: #f6f6f6;
  449. >h5 {
  450. width: 200px;
  451. height: 54px;
  452. display: -webkit-box;
  453. -webkit-box-orient: vertical;
  454. -webkit-line-clamp: 2;
  455. overflow: hidden;
  456. text-overflow: ellipsis;
  457. word-break: break-all;
  458. font-family: Source Han Sans, Source Han Sans;
  459. font-weight: 500;
  460. font-size: 18px;
  461. color: #333333;
  462. line-height: 26px;
  463. text-align: left;
  464. font-style: normal;
  465. text-transform: none;
  466. }
  467. >p {
  468. width: 200px;
  469. height: 22px;
  470. line-height: 20px;
  471. position: absolute;
  472. bottom: 5px;
  473. right: 0;
  474. >span {
  475. display: inline-block;
  476. // width: 100px;
  477. height: 18px;
  478. font-family: Source Han Sans, Source Han Sans;
  479. font-weight: 400;
  480. font-size: 12px;
  481. color: #999999;
  482. text-align: left;
  483. line-height: 14px;
  484. font-style: normal;
  485. text-transform: none;
  486. }
  487. >span:last-child {
  488. // width: 90px;
  489. text-align: right;
  490. margin-left: 20px;
  491. }
  492. }
  493. }
  494. }
  495. >li {
  496. width: 380px;
  497. height: 25px;
  498. white-space: nowrap;
  499. overflow: hidden;
  500. text-overflow: ellipsis;
  501. font-family: PingFang SC, PingFang SC;
  502. font-weight: 500;
  503. font-size: 18px;
  504. color: #333333;
  505. line-height: 21px;
  506. text-align: left;
  507. font-style: normal;
  508. text-transform: none;
  509. margin-bottom: 10px;
  510. em {
  511. display: inline-block;
  512. width: 8px;
  513. height: 8px;
  514. border-radius: 8px;
  515. margin-right: 10px;
  516. background-color: #d9d9d9;
  517. }
  518. }
  519. >li:hover {
  520. color: #139602;
  521. }
  522. >li:hover em {
  523. background-color: #139602;
  524. }
  525. }
  526. }
  527. }
  528. .innerRight {
  529. width: 381px;
  530. height: 290px;
  531. background-color: #fbfbfb;
  532. >.title {
  533. width: 380px;
  534. height: 40px;
  535. line-height: 40px;
  536. border-top: 1px solid #139602;
  537. border-bottom: 1px solid #e7e7e7;
  538. >h4 {
  539. font-family: Microsoft YaHei, Microsoft YaHei;
  540. font-weight: 400;
  541. margin-left: 20px;
  542. font-size: 20px;
  543. color: #000000;
  544. text-align: left;
  545. font-style: normal;
  546. text-transform: none;
  547. >span {
  548. float: right;
  549. font-family: Microsoft YaHei, Microsoft YaHei;
  550. font-weight: 400;
  551. font-size: 14px;
  552. margin-right: 10px;
  553. color: #999999;
  554. text-align: left;
  555. font-style: normal;
  556. text-transform: none;
  557. }
  558. }
  559. }
  560. .rightList {
  561. height: 540px;
  562. margin-top: 20px;
  563. >li {
  564. height: 100px;
  565. margin-bottom: 10px;
  566. >img {
  567. width: 150px;
  568. height: 100px;
  569. }
  570. >p {
  571. width: 219px;
  572. height: 100px;
  573. padding-left: 12px;
  574. font-family: PingFang SC, PingFang SC;
  575. font-weight: 400;
  576. font-size: 16px;
  577. color: #333333;
  578. line-height: 22px;
  579. text-align: left;
  580. font-style: normal;
  581. text-transform: none;
  582. }
  583. >p:hover {
  584. box-shadow: 0 0 16px 1px rgba(0, 0, 0, 0.1);
  585. }
  586. }
  587. }
  588. }
  589. }
  590. </style>